package com.hxkj.cst.chengshuitong.presenter

import android.content.Context
import com.hxkj.cst.chengshuitong.R
import com.hxkj.cst.chengshuitong.control.CaptureControl

/**
 * 作者：LuoYang
 * 时间：2017/6/2:9:29
 * 邮箱：18981443691@163.com
 * 说明：
 */
class CapturePresenter(val context: Context,
                       val view: CaptureControl.View) : CaptureControl.Presenter {

    companion object {
        const val current_capture_sbb = 0
        const val current_capture_hgz = 1
    }

    override fun reSetTitle() {
        val current_capture_location = getCurrentCaptureLocation()
        when (current_capture_location) {
            current_capture_sbb -> {
                view.setTitle(context.getString(R.string.title_scanner_sbb))
            }
            current_capture_hgz -> {
                view.setTitle(context.getString(R.string.title_scanner_hgz))
            }
        }
    }

    override fun getCurrentCaptureLocation(): Int {
        val sharedPreferences = context.getSharedPreferences("cst", Context.MODE_PRIVATE)
        return sharedPreferences.getInt("location", current_capture_sbb)
    }

    override fun setCurrentCaptureLocation(location: Int) {
        val sharedPreferences = context.getSharedPreferences("cst", Context.MODE_PRIVATE)
        val edit = sharedPreferences.edit()
        edit.putInt("location", location)
        edit.apply()
    }
}